﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NetSysData;

namespace BladeTecWebApplication.Admin
{
    public partial class EditQuestionLevels : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                NetSysData.NetSysData data = new NetSysData.NetSysData();
                pnlConfirmationForm.Visible = false;
                int level_id;
                QUESTION_LEVEL questionLevel;
                try
                {
                    level_id = Int32.Parse(Request.QueryString["level_id"]);
                }
                catch (Exception)
                {
                    // show error
                    return;
                }

                if (Request.QueryString["level_id"] != "")
                {
                    questionLevel = data.GetQuestionLevel(level_id) ;
                    if (questionLevel == null)
                    {
                        // show error
                        return;
                    }
                }
                else
                {
                    // show error
                    return;
                }

                txtlevelDescription.Text = questionLevel.LEVEL_DESCRIPTION;
                txtlevelWeight.Text = questionLevel.LEVEL_WEIGHT.ToString();
                
                hfLevelId0.Value = level_id.ToString();
				hfWeight.Value = questionLevel.LEVEL_WEIGHT.ToString();
            }
        }

        protected void btnEditQuestionLevel_Click(object sender, EventArgs e)
        {
            NetSysData.NetSysData data = new NetSysData.NetSysData();

            QUESTION_LEVEL a = data.GetQuestionLevel(Int32.Parse(hfLevelId0.Value));
            a.LEVEL_DESCRIPTION = txtlevelDescription.Text;
			try
			{
				a.LEVEL_WEIGHT = Decimal.Parse(txtlevelWeight.Text);
			}
			catch (Exception)
			{
				pnlNumericError.Visible = true;
				return;
			}

            data.Save();

            pnlQuestionLevelForm.Visible = false;
            pnlConfirmationForm.Visible = true;

            //redirect
            //Server.Transfer("~/Admin/ViewApplicants.aspx", true);
        }
    }
}